package org.jeik.beackBeans.query;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.jeik.beackBeans.BeansBase;
import org.jeik.controllers.NavigationController;
import org.jeik.controllers.NavigationRule;
import org.jeik.data.dao.DataException;
import org.jeik.data.models.CustomerRequest;
import org.jeik.data.services.CustomerRequestsService;

public class QueryRequestsBean extends BeansBase {

	private static final long serialVersionUID = 1L;
	
	private String firstName;
	private String lastName;
	private String mobileNumber;
	private List<CustomerRequest> customerRequests;
	private CustomerRequest requestDetails;
	
	
	public void initCustomersRequests(){
		customerRequests = new ArrayList<CustomerRequest>();
		firstName = "";
		lastName = "";
		mobileNumber = "";
		NavigationController.navigate(NavigationRule.QUERY_CUSTOMER_REQUESTS);
	}
	
	public void filterCustomerRequests(){
				
		customerRequests = new ArrayList<CustomerRequest>();
		try {
			customerRequests = CustomerRequestsService.getInstance().filterCustomersRequests(firstName,lastName,mobileNumber);
		} catch (DataException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
	}
	
	public void viewRequestDetails(Long id){
		
		for(CustomerRequest req : customerRequests){
			if(req.getId().equals(id)){
				requestDetails = req;
				break;
			}
		}
		
		NavigationController.navigate(NavigationRule.CUSTOMER_REQUEST_DETAILS);
	}
	
	public void backToSummary(){
		NavigationController.navigate(NavigationRule.QUERY_CUSTOMER_REQUESTS);
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getMobileNumber() {
		return mobileNumber;
	}

	public void setMobileNumber(String mobileNumber) {
		this.mobileNumber = mobileNumber;
	}

	public List<CustomerRequest> getCustomerRequests() {
		return customerRequests;
	}

	public void setCustomerRequests(List<CustomerRequest> customerRequests) {
		this.customerRequests = customerRequests;
	}

	public CustomerRequest getRequestDetails() {
		return requestDetails;
	}

	public void setRequestDetails(CustomerRequest requestDetails) {
		this.requestDetails = requestDetails;
	}
	
	
}
